package net.slidinglive.utilities.util;

import java.util.ArrayList;
import java.util.List;

import net.slidinglive.utilities.model.Message;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.support.v4.content.CursorLoader;

/**
 * @author Sebastian Hoffmann <bo.hoffi@gmail.com>
 */
public class MessageHelper {

    public static List<Message> getMessages(final String storage, final Activity context, final String[] projection) {

        final List<Message> messages = new ArrayList<Message>();

        final Uri uri = Uri.parse(storage);
        final CursorLoader loader = new CursorLoader(context, uri, projection, null, null, null);
        final Cursor messageCursor = loader.loadInBackground();

        if (messageCursor.moveToFirst()) {
            do {
                final Message m = new Message(messageCursor);
                messages.add(m);

            } while (messageCursor.moveToNext());
        }

        return messages;
    }

    public static List<Message> getMessages(final String storage, final Activity context) {

        return getMessages(storage, context, null);
    }
}